package com.heima.comment.controller;

import com.heima.comment.service.CommentService;
import com.heima.model.common.comment.dtos.CommentDto;
import com.heima.model.common.comment.dtos.CommentLikeDto;
import com.heima.model.common.comment.dtos.CommentSaveDto;
import com.heima.model.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 杨尚杰
 * @data 2024/8/1 21:07
 */
@RestController
@RequestMapping("/api/v1/comment")
@Slf4j
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 保存评论
     * @param commentSaveDto
     * @return
     */
    @PostMapping("/save")
    public ResponseResult saveComment(@RequestBody CommentSaveDto commentSaveDto){
        log.info("保存评论: {}",commentSaveDto);
        return commentService.saveComment(commentSaveDto);
    }

    /**
     * 查询评论列表
     * @param commentDto
     * @return
     */
    @PostMapping("/load")
    public ResponseResult loadComment(@RequestBody CommentDto commentDto){
        log.info("查询评论列表: {}",commentDto);
        return commentService.loadComment(commentDto);
    }

    /**
     * 点赞
     * @param commentLikeDto
     * @return
     */
    @PostMapping("/like")
    public ResponseResult likeComment(@RequestBody CommentLikeDto commentLikeDto){
        log.info("点赞: {}",commentLikeDto);
        return commentService.likeComment(commentLikeDto);
    }

}
